﻿using System;
using System.Collections.Generic;
using MSWord = Microsoft.Office.Interop.Word;

namespace CodeCounsel.Office.DatabindingToolkit
{
    public class DocumentManager
    {
        List<Document> _documents = null;

        public DocumentManager()
        {
            _documents = new List<Document>();
        }

        public Document GetDocument(MSWord.Document wordDocument)
        {
            return _documents.Find(
                delegate(Document searchDocument)
                {
                    return searchDocument.WordDocument == wordDocument;
                });
        }

        public Document CreateDocument(MSWord.Document wordDocument)
        {
            Document document = _documents.Find(
                delegate(Document searchDocument)
                {
                    return searchDocument.WordDocument == wordDocument;
                });
            if (document == null)
            {
                document = new Document(wordDocument);
                _documents.Add(document);
            }
            return document;
        }
    }
}
